/**
 * @param {string} s
 * @return {string}
 */
var longestPalindrome = function (s) {
  if (!s) {
    return 0;
  }

  let length = s.length;
  let result = "";
  let resultLength = 0;

  const isTrue = (str) => {
    let isTrues = true;
    let length1 = str.length;
    let length = Math.floor(str.length) / 2;
    for (let i = 0; i < length; i++) {
      if (str.charAt(i) !== str.charAt(length1 - i - 1)) {
        isTrues = false;
        break;
      }
    }

    return isTrues;
  };

  for (let i = 0; i < length - resultLength; i++) {
    for (let j = i + resultLength; j < length; j++) {
      let str = s.slice(i, j + 1);

      if (isTrue(str) && str.length > resultLength) {
        result = str;
        resultLength = str.length;
      }
    }
  }
  return result;
};

let s =
  "slvafhpfjpbqbpcuwxuexavyrtymfydcnvvbvdoitsvumbsvoayefsnusoqmlvatmfzgwlhxtkhdnlmqmyjztlytoxontggyytcezredlrrimcbkyzkrdeshpyyuolsasyyvxfjyjzqksyxtlenaujqcogpqmrbwqbiaweacvkcdxyecairvvhngzdaujypapbhctaoxnjmwhqdzsvpyixyrozyaldmcyizilrmmmvnjbyhlwvpqhnnbausoyoglvogmkrkzppvexiovlxtmustooahwviluumftwnzfbxxrvijjyfybvfnwpjjgdudnyjwoxavlyiarjydlkywmgjqeelrohrqjeflmdyzkqnbqnpaewjdfmdyoazlznzthiuorocncwjrocfpzvkcmxdopisxtatzcpquxyxrdptgxlhlrnwgvee";
console.time();
longestPalindrome(s);
console.timeEnd();
